package com.mydemo.common.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.security.core.GrantedAuthority;

import java.util.Objects;

/**
 * 权限类
 * @author Last_Island
 * @version 1.0
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Permission implements GrantedAuthority {
    private static final long serialVersionUID = 1L;

    /**
     * 权限ID
     */
    private Long authorityId;
    /**
     * 权限标识
     */
    private String authorityKey;

    public Permission() {
    }

    public Permission(String authorityKey) {
        this.authorityKey = authorityKey;
    }

    public Permission(Long authorityId, String authorityKey) {
        this.authorityId = authorityId;
        this.authorityKey = authorityKey;
    }

    public Long getAuthorityId() {
        return authorityId;
    }

    public void setAuthorityId(Long authorityId) {
        this.authorityId = authorityId;
    }

    public String getAuthority() {
        return authorityKey;
    }

    public void setAuthority(String authorityKey) {
        this.authorityKey = authorityKey;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Permission that)) return false;
        return Objects.equals(authorityKey, that.authorityKey);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(authorityKey);
    }
}
